/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dp1.titandevelop.titano.view.prod;

import dp1.titandevelop.titano.persistent.Asignacion;
import dp1.titandevelop.titano.service.AsignacionService;
import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author Yulian
 */
public class ModulosT_PRO_BusquedaAsig extends javax.swing.JDialog {

    public List<Integer> listaIDAsignacion ;
    public List<Asignacion> listaAsignacion;
    
    public ModulosT_PRO_BusquedaAsig(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        AsignacionService as= new AsignacionService ();
        listaIDAsignacion=as.SacaAsignaciones(); 
        
        this.tablaCorridaAlgo.setModel(ModeloTabla);
    }
    
    private AbstractTableModel ModeloTabla = new AbstractTableModel() {
        //Atributos de los datos de la tabla
        private String[] titles = {"Cód.Asignación","Descripción"};

        @Override
        public int getRowCount() {
            return listaIDAsignacion.size(); // listaIDAsignacion.size();//tipos.size(); // cuantos registros (filas)
        }

        @Override
        public int getColumnCount() {
            return 2; // cuantas columnas
        }

        @Override
        public String getColumnName(int col) {
            return titles[col];
        }

        @Override
        public Object getValueAt(int rowIndex, int columnIndex) {
            Object resultado = null;
            AsignacionService serv= new AsignacionService ();
            int idAsig = listaIDAsignacion.get(rowIndex);
            
            switch (columnIndex) {
                case 0: resultado = idAsig;break;
                case 1: resultado =serv.ObtenerDescripcion(idAsig);break;
//                case 2: resultado =serv.ObtenerCantEmpleados(idAsig);break;
//                case 3: resultado =serv.ObtenerCantMaquinas(idAsig);break;
//                case 4: resultado =serv.ObtenerProduccion(idAsig);break;
//                case 5: resultado =serv.ObtenerRotura(idAsig);break;
            }
            return resultado;
        }
    };
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        PanelCorridaAlgoritmo = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tablaCorridaAlgo = new javax.swing.JTable();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        PanelCorridaAlgoritmo.setBorder(javax.swing.BorderFactory.createTitledBorder("Lista de Asignaciones"));
        PanelCorridaAlgoritmo.setFont(new java.awt.Font("Tekton Pro", 0, 11)); // NOI18N

        tablaCorridaAlgo.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Código Asig", "Descripción", "Cant. Empleados", "Cant. Máquinas", "T. Producido", "T.Merma"
            }
        ));
        tablaCorridaAlgo.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tablaCorridaAlgoMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tablaCorridaAlgo);

        javax.swing.GroupLayout PanelCorridaAlgoritmoLayout = new javax.swing.GroupLayout(PanelCorridaAlgoritmo);
        PanelCorridaAlgoritmo.setLayout(PanelCorridaAlgoritmoLayout);
        PanelCorridaAlgoritmoLayout.setHorizontalGroup(
            PanelCorridaAlgoritmoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PanelCorridaAlgoritmoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 635, Short.MAX_VALUE)
                .addContainerGap())
        );
        PanelCorridaAlgoritmoLayout.setVerticalGroup(
            PanelCorridaAlgoritmoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PanelCorridaAlgoritmoLayout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 147, Short.MAX_VALUE)
                .addContainerGap())
        );

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/retroceder.png"))); // NOI18N
        jButton1.setToolTipText("Salir");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(8, 8, 8)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(PanelCorridaAlgoritmo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jButton1)))
                .addGap(8, 8, 8))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(8, 8, 8)
                .addComponent(PanelCorridaAlgoritmo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(8, 8, 8)
                .addComponent(jButton1)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void tablaCorridaAlgoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tablaCorridaAlgoMouseClicked
            if (evt.getClickCount() == 2) {
                AsignacionService asigservice= new AsignacionService ();
                int idObtenido = this.listaIDAsignacion.get(this.tablaCorridaAlgo.getSelectedRow());
                this.listaAsignacion=(ArrayList)asigservice.buscarIdAsignacion(idObtenido);
                ModulosT_PRO_OrdProNuevo.asig=this.listaAsignacion;
                ModulosT_PRO_OrdProNuevo.txtAsignacion.setText(String.valueOf(idObtenido));
       
                this.dispose();
        }
    }//GEN-LAST:event_tablaCorridaAlgoMouseClicked

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        this.dispose();
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ModulosT_PRO_BusquedaAsig.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ModulosT_PRO_BusquedaAsig.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ModulosT_PRO_BusquedaAsig.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ModulosT_PRO_BusquedaAsig.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                ModulosT_PRO_BusquedaAsig dialog = new ModulosT_PRO_BusquedaAsig(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel PanelCorridaAlgoritmo;
    private javax.swing.JButton jButton1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tablaCorridaAlgo;
    // End of variables declaration//GEN-END:variables
}
